package com.xbongbong.pro.enums.raiders.enums;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 价值攻略是否付费枚举
 * @author zcp
 * @version v1.0
 * @date 19/9/18 018 20:44
 * @update 19/9/18 018 20:44
 * @since v1.0
 */
@Getter
public enum RaidersFreeEnum {
    /**
     * 是否付费枚举，对应数据库内free字段
     */
    FREE(1, "enum.raidersFree.name.free", "enum.raidersFree.memo.free"),

    VIP(2, "enum.raidersFree.name.vip", "enum.raidersFree.memo.vip"),

    UNKNOWN(404, "", "enum.raidersFree.memo.unknown"),

    ;

    /**
     * 枚举值 --
     */
    private final int code;
    /**
     * 枚举信息--中文名称
     */
    private final String name;
    /**
     * 枚举信息--中文名称
     */
    private final String memo;

    RaidersFreeEnum(int code, String name, String memo) {
        this.code = code;
        this.name = name;
        this.memo = memo;
    }

    /**
     * 格式化下拉选项
     * @return com.alibaba.fastjson.JSONArray
     * @author zcp
     * @date 19/10/18 018 16:10
     * @update 19/10/18 018 16:10
     * @since v1.0
     * @version v1.0
     */
    public static JSONArray formatOption() {
        JSONArray jsonArray = new JSONArray();
        for (RaidersFreeEnum cache : values()) {
            if (Objects.equals(cache, UNKNOWN)) {
                continue;
            }
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("key", cache.getCode());
            jsonObject.put("value", cache.getName());
            jsonArray.add(jsonObject);
        }
        return jsonArray;
    }

    public String getMemo() {
        return I18nMessageUtil.getMessage(memo);
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
